using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Park.Net.Model;
using Park.Net.EFCoreEnv;
using Park.Net.IRepository;
using Park.Net.Repository;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;

namespace Park.Net.IRepository
{
    public class CarParkRepository :BaseRepository<CarPark>,ICarParkRepository
    {
         private readonly ParkDbContext  _context;

        public CarParkRepository(ParkDbContext db) : base(db)
        {
            ParkDb = db;
            _context=db;
        }

         public async override Task<List<CarPark>> FindAllAsync()
        {
            return await _context.CarPark.ToListAsync();
        }

        public async override Task<List<CarPark>> FindManyAsync(Expression<Func<CarPark, bool>> exp)
        {
            return await _context.CarPark.Where(exp).ToListAsync();
        }

        public async override Task<CarPark> FindOneAsync(Expression<Func<CarPark, bool>> exp)
        {
            return await _context.CarPark.FirstOrDefaultAsync(exp);
        }

        public override async Task<CarPark> FindOneAsync(int id)
        {
            return await _context.CarPark.FirstOrDefaultAsync(art=>art.ID == id);
        }
    }
}